package com.juhui.macao;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.google.gson.Gson;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MainActivity extends AppCompatActivity {

    public static final String OpenWeiXinBusinessId = "wxb66afb2f26ddb509";//商户的：wxb66afb2f26ddb509  应用的：wxe537a9d6c51db828
    private EditText orderid;//测试范围 1291~1332

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        orderid = findViewById(R.id.orderid);

        findViewById(R.id.aaa).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                reqPsyString();
            }
        });
    }

    private void reqPsyString() {
        String oid = orderid.getText().toString().trim();
        RetrofitUtil.addUrlApi(getApplication(), OrderApi.class).
                bocWe(oid, 1).enqueue(new Callback<BocWeResp>() {
            @Override
            public void onResponse(Call<BocWeResp> call, Response<BocWeResp> response) {
                BocWeResp resp = response.body();
                if (resp != null) {
                    if (resp.getCode() == 1) {
                        BocWeResp.DataBean data = resp.getData();
                        BocWeResp.DataBean.PayOrderStringBean datas = data.getPayOrderString();
//               /*gson*/
                        Gson g = new Gson();
                        String json = g.toJson(datas);
                        json = json.replace("\\u003d", "=");
//               /*gson*/
//*json*/
//                JsonObject jsonObject = new JsonObject();
//                jsonObject.addProperty("paySignType", datas.getPaySignType());
//                jsonObject.addProperty("payTimestamp", datas.getPayTimestamp());
//                jsonObject.addProperty("payNoncestr", datas.getPayNoncestr());
//                jsonObject.addProperty("paySign", datas.getPaySign());
//                jsonObject.addProperty("partnerId", datas.getPartnerId());
//                jsonObject.addProperty("package", datas.getPackageX());
//                jsonObject.addProperty("prepayId", datas.getPrepayId());
//                jsonObject.addProperty("appid", datas.getAppid());
//                String json = jsonObject.toString();
//*json*/
                        DebugLogUtil.getInstance().Debug(json);
//                        BocAasPayManager.getInstence(MyApplication.getApplication()).pay(MpayActivity.this, "WECHATPAY", json);
                        MyApplication.getBocInstance().pay(MainActivity.this, "WECHATPAY", json);
                    }
                }
            }

            @Override
            public void onFailure(Call<BocWeResp> call, Throwable t) {
                Toast.makeText(MainActivity.this, "errorrrrr", Toast.LENGTH_LONG).show();
                DebugLogUtil.getInstance().Debug(t.getLocalizedMessage());
//                ToastUtils.show(getResources().getString(R.string.request_fail));
//                finish();
            }
        });
    }
}